package components
{
    import flash.display.*;
    import flash.events.Event;
    
    import mx.core.*;
    
    import org.papervision3d.cameras.CameraType;
    import org.papervision3d.view.*; 

    public class CanvasView3D extends UIComponent
    {    
        private var _canvas:Sprite;
        public var theview:BasicView;
        private var _viewWidth:Number = 0;
        private var _viewHeight:Number = 0;
        private var _autoScale:Boolean = true;
        private var _interactive:Boolean = false;
        private var _autoClipping:Boolean = true;
        private var _autoCulling:Boolean = true;
        private var _cameraType:String = CameraType.FREE;
                
        public function CanvasView3D()
        {
            super();
        }
                
        public function start():void
        {
            
            canvas = new Sprite();
            
            theview = new BasicView( viewWidth, viewHeight, autoScale, interactive, cameraType );
            theview.viewport.autoClipping = autoClipping;
            theview.viewport.autoCulling = autoCulling;
            
            canvas.addChild( theview );            
            addChild( canvas );  
            
            addEventListener( Event.ENTER_FRAME, loop3D);
            
        }
        
        private function loop3D( event:Event ):void
		{
			view.renderer.renderScene(view.scene, view.camera, view.viewport);
		}
                
        public function set viewWidth( value:Number ):void
        {
            _viewWidth = value;    
        }
        
        public function get viewWidth():Number
        {
            return _viewWidth;    
        }

        public function set viewHeight(value:Number):void
        {
            _viewHeight = value;    
        }
        
        public function get viewHeight():Number
        {
            return _viewHeight;    
        }

        public function set autoScale( value:Boolean ):void
        {
            _autoScale = value;    
        }
        
        public function get autoScale():Boolean
        {
            return _autoScale;    
        }

        public function set interactive( value:Boolean ):void
        {
            _interactive = value;    
        }
        
        public function get interactive():Boolean
        {
            return _interactive;    
        }

        public function set autoClipping( value:Boolean ):void
        {
            _autoClipping = value;    
        }
        
        public function get autoClipping():Boolean
        {
            return _autoClipping;    
        }

        public function set autoCulling( value:Boolean ):void
        {
            _autoCulling = value;    
        }
        
        public function get autoCulling():Boolean
        {
            return _autoCulling;    
        }
        
        public function set canvas( value:Sprite ):void
        {
        	_canvas = value;
        }
        
        public function get canvas():Sprite
        {
            return _canvas;
        }

        public function get view():BasicView
        {
            return theview;
        }
        
        public function set cameraType( value:String ):void
        {
        	_cameraType = value;
        }
        
         public function get cameraType():String
        {
            return _cameraType;
        }
    }
}